﻿@model ProductDetailsModel
@using Microsoft.AspNetCore.Http.Extensions
@inject SeoSettings seoSettings
@using Grand.Framework.Themes
@using Grand.Framework.UI
@inject IWorkContext workContext
@inject IThemeContext themeContext
@inject IPageHeadBuilder pagebuilder

@{
    var themeName = themeContext.WorkingThemeName;
    var supportRtl = workContext.WorkingLanguage.Rtl;
    if (supportRtl)
    {
        pagebuilder.AppendCssFileParts(ResourceLocation.Head, string.Format("~/Themes/{0}/Content/css/product/product.rtl.css", themeName));
    }
    else
    {
        pagebuilder.AppendCssFileParts(ResourceLocation.Head, string.Format("~/Themes/{0}/Content/css/product/product.css", themeName));
    }
}
@{
    Layout = "_ColumnsOne";

    //title, meta
    pagebuilder.AddTitleParts(!String.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : Model.Name);
    pagebuilder.AddMetaDescriptionParts(Model.MetaDescription);
    pagebuilder.AddMetaKeywordParts(Model.MetaKeywords);

    //canonical URL
    if (seoSettings.CanonicalUrlsEnabled)
    {
        var productUrl = Url.RouteUrl("Product", new { SeName = Model.SeName }, this.Url.ActionContext.HttpContext.Request.Scheme);
        pagebuilder.AddCanonicalUrlParts(productUrl);
    }

    //open graph META tags
    if (seoSettings.OpenGraphMetaTags)
    {
        pagebuilder.AddHeadCustomParts("<meta property=\"og:type\" content=\"product\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"og:title\" content=\"" + Html.Encode(Model.Name) + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"og:description\" content=\"" + Html.Encode(Model.MetaDescription) + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"og:image\" content=\"" + Model.DefaultPictureModel.ImageUrl + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"og:image:url\" content=\"" + Model.DefaultPictureModel.ImageUrl + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"og:url\" content=\"" + this.Url.ActionContext.HttpContext.Request.GetEncodedUrl() + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"og:site_name\" content=\"" + Html.Encode(Model.CurrentStoreName) + "\" />");
    }

    //Twitter META tags
    if (seoSettings.TwitterMetaTags)
    {
        pagebuilder.AddHeadCustomParts("<meta property=\"twitter:card\" content=\"summary\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"twitter:site\" content=\"" + Html.Encode(Model.CurrentStoreName) + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"twitter:title\" content=\"" + Html.Encode(Model.Name) + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"twitter:description\" content=\"" + Html.Encode(Model.MetaDescription) + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"twitter:image\" content=\"" + Model.DefaultPictureModel.ImageUrl + "\" />");
        pagebuilder.AddHeadCustomParts("<meta property=\"twitter:url\" content=\"" + this.Url.ActionContext.HttpContext.Request.GetEncodedUrl() + "\" />");
    }
}
<!--product breadcrumb-->
@section Breadcrumb
{
    <partial name="_ProductBreadcrumb" model="Model.Breadcrumb" />
}
@await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_after_breadcrumb", additionalData = Model.Id })
<div class="page product-details-page product-standard product-grouped">
    @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_top", additionalData = Model.Id })
    <form asp-route="Product" asp-route-sename="@Model.SeName" method="post" id="product-details-form">
        <div itemscope itemtype="http://schema.org/Product" data-productid="@Model.Id">
            <div class="product-essential">
                <b-container>
                    <b-row>
                        <vc:widget widget-zone="productdetails_before_pictures" additional-data="@Model.Id"></vc:widget>
                        <!--product pictures-->
                        <partial name="_ProductDetailsPictures" model="Model" />
                        <vc:widget widget-zone="productdetails_after_pictures" additional-data="@Model.Id"></vc:widget>
                        <b-col xl="6" lg="6" md="7" cols="12" class="overview pl-md-3 pl-0 pr-0">
                            @if (!string.IsNullOrEmpty(Model.Flag))
                            {
                                <div class="product-label">
                                    <b-badge variant="info">@Model.Flag</b-badge>
                                </div>
                            }
                            <partial name="_Discontinued" model="Model" />
                            <div class="product-name">
                                <h1 class="generalTitle mb-3" itemprop="name">
                                    @Model.Name
                                </h1>
                            </div>
                            @if (!String.IsNullOrEmpty(Model.ShortDescription))
                            {
                                <div class="short-description mb-3">
                                    @Html.Raw(Model.ShortDescription)
                                </div>
                            }
                            @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_overview_top", additionalData = Model.Id })
                            <!--product reviews-->
                            @if (Model.ProductReviewOverview.AllowCustomerReviews)
                            {
                                <partial name="_ProductReviewOverview" model="Model.ProductReviewOverview" />
                            }
                            <!--product manufacturers-->
                            @if (Model.ProductManufacturers.Any())
                            {
                                <partial name="_ProductManufacturers" model="Model.ProductManufacturers" />
                            }
                            <!--warehouses-->
                            @if (Model.AllowToSelectWarehouse)
                            {
                                <partial name="_ProductWarehouses" model="Model" />
                            }
                            <!--compare, email a friend-->
                            <b-btn-group class="mt-2 mb-3 w-100">
                                @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_inside_overview_buttons_before", additionalData = Model.Id })
                                <partial name="_CompareProductsButton" model="Model" />
                                <partial name="_ProductEmailAFriendButton" model="Model" />
                                <partial name="_ProductAskQuestionButton" model="Model" />
                                @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_inside_overview_buttons_after", additionalData = Model.Id })
                            </b-btn-group>
                            <partial name="_ShareButton" model="Model" />
                            @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_overview_bottom", additionalData = Model.Id })
                        </b-col>
                    </b-row>
                </b-container>
            </div>

            <b-col cols="12" class="px-0 my-3">
                <div>
                    <b-tabs content-class="mt-3" align="center">
                        <b-tab title="@T("Products.Description")" active>
                            @Html.Raw(Model.FullDescription)
                        </b-tab>
                        @if (Model.ProductTags.Any())
                        {
                            <b-tab title="@T("Products.Tags")">
                                <partial name="_ProductTags" model="Model.ProductTags" />
                            </b-tab>
                        }
                        @if (Model.ProductSpecifications.Any())
                        {
                            <b-tab title="@T("Products.Specs")">
                                <partial name="_ProductSpecifications" model="Model.ProductSpecifications" />
                            </b-tab>
                        }
                        @if (Model.ProductReviewOverview.AllowCustomerReviews)
                        {
                            <b-tab id="review-tab" title="@T("Products.Reviews")" :active="active ? true : false">
                                @await Component.InvokeAsync("ProductReviews", new { productId = Model.Id })
                            </b-tab>
                        }
                        @if (Model.AskQuestionOnProduct)
                        {
                            <b-tab title="@T("Products.ContactUs")">
                                <partial name="_AskQuestionOnProduct" model="Model.ProductAskQuestion" />
                            </b-tab>
                        }
                    </b-tabs>
                </div>
            </b-col>
            @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_before_collateral", additionalData = Model.Id })
            <div class="product-collateral">
                <div>
                    <!--associated products-->
                    @foreach (var variant in Model.AssociatedProducts)
                    {
                            <b-card no-body class="overflow-hidden associatedItem mb-3">
                                <b-row no-gutters>
                                    <b-col lg="3" md="4">
                                        <b-card-img id="main-product-img-@variant.Id" alt="@variant.DefaultPictureModel.AlternateText" src="@variant.DefaultPictureModel.ImageUrl" class="rounded-0"></b-card-img>
                                    </b-col>
                                    <b-col lg="9" md="8">
                                        <b-card-body class="overview" title="@variant.Name">
                                            <b-card-text>
                                                @Html.Raw(variant.ShortDescription)
                                            </b-card-text>
                                            <!--availability-->
                                            <partial name="_Availability" model="variant" />
                                            <!--SKU, MAN, GTIN, vendor-->
                                            <partial name="_SKU_Man_GTIN_Ven" model="variant" />
                                            <!--delivery-->
                                            @if ((variant.FreeShippingNotificationEnabled && Model.IsFreeShipping) || !string.IsNullOrWhiteSpace(variant.DeliveryDate)
                                         || variant.NotReturnable || variant.AdditionalShippingCharge > 0)
                                            {
                                                <partial name="_DeliveryInfo" model="variant" />
                                            }
                                            <!--sample download-->
                                            @if (variant.HasSampleDownload)
                                            {
                                                <partial name="_DownloadSample" model="variant" />
                                            }
                                            <!--attributes-->
                                            @{
                                                if (variant.ProductAttributes.Any())
                                                {
                                                    var dataDictAttributes = new ViewDataDictionary(ViewData);
                                                    dataDictAttributes.TemplateInfo.HtmlFieldPrefix = string.Format("attributes_{0}", variant.Id);
                                                    <partial name="VueProductAttributes" model="variant.ProductAttributes" view-data="dataDictAttributes" />
                                                }
                                            }
                                            <!--gift card-->
                                            @{
                                                if (variant.GiftCard.IsGiftCard)
                                                {
                                                    var dataDictGiftCard = new ViewDataDictionary(ViewData);
                                                    dataDictGiftCard.TemplateInfo.HtmlFieldPrefix = string.Format("giftcard_{0}", variant.Id);
                                                    <partial name="_GiftCardInfo" model="variant.GiftCard" view-data="dataDictGiftCard" />
                                                }
                                            }
                                            <!--price breaks-->
                                            @if (variant.TierPrices.Any() && !(variant.TierPrices.Count == 1))
                                            {
                                                <partial name="_ProductTierPrices" model="variant.TierPrices" />
                                            }
                                            @{
                                                var dataDictAddToCart = new ViewDataDictionary(ViewData);
                                                dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", variant.Id);
                                            }
                                            <!--price & add to cart-->
                                            @{
                                                var dataDictPrice = new ViewDataDictionary(ViewData);
                                                dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", variant.Id);
                                                <partial name="_ProductPrice" model="variant.ProductPrice" view-data="dataDictPrice" />
                                            }
                                                    @{
                                                        <partial name="_AddToCart" model="variant.AddToCart" view-data="dataDictAddToCart" />
                                                        var dataDictAddToWishlist = new ViewDataDictionary(ViewData);
                                                        dataDictAddToWishlist.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", variant.Id);
                                                        <div class="mt-2">
                                                            <partial name="_AddToWishlist" model="variant.AddToCart" view-data="dataDictAddToWishlist" />
                                                        </div>
                                                    }
                                        </b-card-body>
                                    </b-col>
                                </b-row>
                            </b-card>
                    }

                    @if (Model.AssociatedProducts.Count == 0)
                    {
                        <div class="no-associated-products">
                            @T("Products.NoAssociatedProducts")
                        </div>
                    }
                </div>
            </div>
        </div>
        @await Component.InvokeAsync("RelatedProducts", new { productId = Model.Id })
    </form>
    @await Component.InvokeAsync("Widget", new { widgetZone = "productdetails_bottom", additionalData = Model.Id })
</div>
